### texreg method for polr objects
extract.krls <- function(model, include.r2 = TRUE,
                         include.nobs = TRUE, ...) {

  r2 <- model$R2
  
  ddpcr::quiet(model.summary <- summary(model))
  
  coef <- model.summary$coefficients[,1]
  se <- model.summary$coefficients[,2]
  pval <- model.summary$coefficients[,4]
  
  names <- rownames(model.summary$coefficients)
  
  n <- dim(model[[1]])[1]

  gof <- numeric()
  gof.names <- character()
  gof.decimal <- logical()
  
  if (include.r2 == TRUE) {
    gof <- c(gof, r2)
    gof.names <- c(gof.names, "R2")
    gof.decimal <- c(gof.decimal, TRUE)
  }

  if (include.nobs == TRUE) {
    gof <- c(gof, n)
    gof.names <- c(gof.names, "Number of Observations")
    gof.decimal <- c(gof.decimal, FALSE)
  }
  
  tr <- createTexreg(
    coef.names = names,
    coef = coef,
    se = se,
    pvalues = pval,
    gof.names = gof.names,
    gof = gof,
    gof.decimal = gof.decimal
  )
  return(tr)
}
